package com.xbongbong.pro.enums.raiders.enums;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.pro.constant.RaidersConstant;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 攻略步骤枚举
 *
 * @author zcp
 * @version v1.0
 * @date 19/9/27 027 16:09
 * @update 19/9/27 027 16:09
 * @since v1.0
 */
@Getter
public enum RaidersStepEnum {
    /**
     * 攻略步骤枚举
     */
    PREVIEW("preview", "enum.raidersStep.name.preview", "enum.raidersStep.instruction.preview", 1),

    VIDEO("video", "enum.raidersStep.name.video", "enum.raidersStep.instruction.video", 1),

    OPERATION("operation", "enum.raidersStep.name.operation", "enum.raidersStep.instruction.operation", 1),

    INVITATION("invitation", "enum.raidersStep.name.invitation", "enum.raidersStep.instruction.invitation", 0),

    DOCUMENT("document", "enum.raidersStep.name.document", "enum.raidersStep.instruction.document", 1),

    MIRROR("mirror", "enum.raidersStep.name.mirror", "enum.raidersStep.instruction.mirror", 1),

    UNKNOWN("404", "enum.raidersStep.name.unknown", "", 0),

    ;

    /**
     * 枚举值 --
     */
    private final String step;
    /**
     * 枚举信息--中文名称
     */
    private final String name;
    /**
     * 枚举信息--描述
     */
    private final String instruction;

    /**
     * 是否启用
     */
    private final Integer enable;

    RaidersStepEnum(String step, String name, String instruction, Integer enable) {
        this.step = step;
        this.name = name;
        this.instruction = instruction;
        this.enable = enable;
    }

    /**
     * 通过步骤获取枚举
     * @param step
     * @return com.xbongbong.pro.enums.raiders.enums.RaidersStepEnum
     * @author zcp
     * @date 19/9/29 029 16:12
     * @update 19/9/29 029 16:12
     * @since v1.0
     * @version v1.0
     */
    public static RaidersStepEnum getByStep(String step) {
        for (RaidersStepEnum cache : values()) {
            if (Objects.equals(cache.step, step) && Objects.equals(cache.enable, 1)) {
                return cache;
            }
        }
        return UNKNOWN;
    }
    /**
     * 对预览、视频介绍、实操、邀请等加入instruction
     * @param jsonObject 步骤内容
     * @param stepEnum 步骤枚举
     * @return com.alibaba.fastjson.JSONObject
     * @author zcp
     * @date 19/9/29 029 16:10
     * @update 19/9/29 029 16:10
     * @since v1.0
     * @version v1.0
     */
    public static JSONObject addInstruction(JSONObject jsonObject, RaidersStepEnum stepEnum) {
        if (jsonObject != null) {
            jsonObject.put("instruction", stepEnum.getInstruction());
        }
        return jsonObject;
    }

    /**
     * 返回所有启用的步骤
     *
     * @return java.util.List<java.lang.String>
     * @author 徐俊杰
     * @date 2019/10/15 10:23
     * @since v1.0
     */
    public static List<String> getAllStep() {
        List<String> stepList = new ArrayList<>();
        for (RaidersStepEnum cache : values()) {
            if (Objects.equals(cache.enable, RaidersConstant.ENABLE)) {
                stepList.add(cache.step);
            }
        }
        return stepList;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public String getInstruction() {
        return I18nMessageUtil.getMessage(instruction);
    }

}
